package com.jied.duodian.web;

import com.jied.duodian.entity.DdLeibie;
import com.jied.duodian.service.Impl.DdLeibieServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Description:
 *
 * @author LiJie
 * @date Created on 2020/10/30
 * WWW https://github.com/j6l
 */
@RestController
@RequestMapping("/lei")
@Slf4j
public class leiController {

    @Autowired
    DdLeibieServiceImpl ddLeibieService;

    /**
     * 获取首页分类
     *
     * @param req
     * @return
     */
    @GetMapping("/get")
    public List<DdLeibie> getLeiAll(HttpServletRequest req) {
        DdLeibie ddLeibie = new DdLeibie();
        ddLeibie.setShuxing( 0 );
        List<DdLeibie> leibie = ddLeibieService.getLeibie( ddLeibie, 2 );
        for (DdLeibie d : leibie) {
            List<DdLeibie> leibie1 = ddLeibieService.getLeibie( d, 0 );
            d.setList( leibie1 );
        }

        log.info( "{}请求了{}地址", req.getRemoteAddr(), req.getRequestURI() );
        return leibie;
    }

    /**
     * 获取商品的子分类
     *
     * @return
     */
    @PostMapping("/getsuxing")
    public List<DdLeibie> getsuxing() {
        DdLeibie ddLeibie = new DdLeibie();
        ddLeibie.setShuxing( 0 );
        List<DdLeibie> leibie = ddLeibieService.getLeibie( ddLeibie, 3 );
        return leibie;
    }
}
